def properties_copy(original_dict, exclude_list=None):
    '''
    深拷贝 一个字典 并可以 不拷贝 某些属性
    :param original_dict:
    :param exclude_list:
    :return:
    '''
    if exclude_list is None:
        exclude_list = []
    new_dict = {}
    for key, values in original_dict.items():
        if key in exclude_list:
            pass
        else:
            new_dict[key] = values

    return new_dict


def exclude_dict_some_properties(original_dict: dict, exclude_properties_list: list):
    """  排除掉 字典中 指定的属性 """
    if exclude_properties_list:
        keys = list(original_dict.keys())
        for key in keys:
            if key in exclude_properties_list:
                original_dict.pop(key)
    else:
        raise RuntimeWarning("没有指定 需要排除的 属性")
    return original_dict


def exclude_dict_none_properties(original_dict: dict):
    '''
    排除掉 字典中 无效的属性
    :param original_dict:
    :return:
    '''
    keys = list(original_dict.keys())
    for key in keys:
        value = original_dict.get(key, None)
        if not value:
            original_dict.pop(key)


def replace_dict_none_properties(original_dict: dict, replace: str = "") -> dict:
    '''
    排除掉 字典中 无效的属性
    :param replace:
    :param original_dict:
    :return:
    '''
    keys = list(original_dict.keys())
    for key in keys:
        if original_dict.get(key, None) is None:
            original_dict[key] = replace
    return original_dict


def _convert_to_dict(obj):
    '''
    把Object对象转换成Dict对象
    :param obj:
    :return:
    '''
    if isinstance(obj, list) or isinstance(obj, set) or isinstance(obj, tuple):
        raise RuntimeWarning("只有 obj 才能转换为 字典")
    d = {}
    d.update(obj.__dict__)
    return d


def _convert_to_dicts(obj_list: list or set):
    '''
    把对象列表转换为字典列表
    :param obj_list:
    :return:
    '''
    obj_arr = []
    for o in obj_list:
        # 把Object对象转换成Dict对象
        d = _convert_to_dict(o)
        obj_arr.append(d)

    return obj_arr


def obj_to_dict(obj):
    '''
    把对象(支持单个对象、list、set)转换成字典
    :param obj:
    :return:
    '''
    if isinstance(obj, list) or isinstance(obj, set):
        return _convert_to_dicts(obj)
    else:
        return _convert_to_dict


def cascade_2_dict(cascade: dict, new_dict: dict, upper_key: str = None):
    for (k, v) in cascade.items():
        if isinstance(v, dict):
            cascade_2_dict(v, new_dict, upper_key=k)
        else:
            key = f"{upper_key}_{k}" if upper_key else k
            new_dict[key] = v
    return new_dict


if __name__ == "__main__":
    a = {"a": "A", "b": 1, "c": {"A": "a", "B": 0}}
    b = {}
    c = cascade_2_dict(a, b)
    print(b.keys())
    print(b)
    print(list(c.keys()))
    print(c)
